/*
 * Maximum Path Sum II Solution.
 */

package Graph;

/**
 * Implementation of a vertex for use in a graph.
 * 
 * @author Michael
 * @see Graph
 * @see AdjacencyListGraph
 * @see WeightedAdjacencyListGraph
 */

public class Vertex implements Cloneable {
    
    /** Human readable identifier for the vertex. */
    public String name;
    
    /** Identifier for the vertex. */
    private int id;
    
    /** Indicates the vertex has not been assigned a unique identifier. */
    private final int UNASSIGNED_ID = -1;
        
    /**
     * Instantiate a new <code>Vertex</code> with the given name and unknown
     * id.
     * 
     * @param name 
     */
    public Vertex(String name)
    {
        this.name = name;
        id = UNASSIGNED_ID;
    }
    
    
    /**
     * Instantiate a new <code>Vertex</code> with the given name and id.
     * 
     * @param name  Name assigned to the vertex.
     */
    public Vertex(int index, String name)
    {
        this.id = index;
        this.name = name;
    }
    
    
    /**
     * Copy constructor.  
     * Creates a copy of the <code>Vertex</code> provided as a parameter.
     * 
     * @param v
     */
    public Vertex(Vertex v)
    {
        this.id = v.getIdentifier();
        this.name = v.getName();
    }
    
    
    /**
     * Creates and returns a new copy of the calling <code>Vertex</code>.  Both
     * the <code>Vertex.id</code> and <code>Vertex.name</code> fields to the 
     * new <code>Vertex</code>.
     * 
     * @return A new <code>Vertex</code>.
     */
    @Override
    public Vertex clone()
    {
        return new Vertex(this.id, this.name);
    }
    
    
    /**
     * Provides the <code>Vertex</code> an identifier.
     * 
     * @param id New identifier for the <code>Vertex</code>.
     */
    public void setIdentifier(int id)
    {
        this.id = id;
    }
    
    
    /**
     * Tells the caller the <code>Vertex</code> id.
     * 
     * @return The <code>Vertex</code> id.
     */
    public int getIdentifier()
    {
        return id;
    }
    
    
    /**
     * Provides the <code>Vertex</code> a name.
     * 
     * @param name 
     */
    public void setName(String name)
    {
        this.name = name;
    }
    
    
    /**
     * Tells the caller the <code>Vertex</code> name.
     * 
     * @return Name of the <code>Vertex</code>
     */
    public String getName () 
    {
        return name;
    }    
    
}
